using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.WebControls;

public partial class admin_users : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void grdUsers_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)
    {
        DataTable dt = new UserAccBus().LoadAllUsers();
        grdUsers.DataSource = dt;
    }

    protected void grdUsers_UpdateCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        string userID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserID"].ToString();
        string fullName = (editedItem.FindControl("txtFullName") as RadTextBox).Text;
        DateTime dateOfBirth = Convert.ToDateTime((editedItem.FindControl("rdpDateOfBirth") as RadDatePicker).SelectedDate);
        string address = (editedItem.FindControl("txtAddress") as RadTextBox).Text;
        string email = (editedItem.FindControl("txtEmail") as RadTextBox).Text;
        bool disabled = (editedItem.FindControl("chkDisabled") as CheckBox).Checked;

        UserAcc dto = new UserAcc(userID, fullName, dateOfBirth, address, email, disabled);
        try
        {
            new UserAccBus().Update(dto);
        }
        catch { e.Canceled = true; }
    }

    protected void grdUsers_DeleteCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
    {
        int itemIndex = e.Item.ItemIndex;
        string userID = e.Item.OwnerTableView.DataKeyValues[itemIndex]["UserID"].ToString();
        new UserAccBus().Delete(userID);
    }
}
